﻿using System;
using Microsoft.Extensions.DependencyInjection;
using 依赖综合案例.ConfigServices;
using 依赖综合案例.LogServices;
using 依赖综合案例.MailServices;

namespace 依赖综合案例
{
    internal class Program
    {
        static void Main(string[] args)
        {
            ServiceCollection services = new ServiceCollection();
            // services.AddScoped<IConfigProjects, EvnVarConfigProjects>();
            services.AddScoped<IConfigProjects, EvnVarConfigProjects>();
            services.AddLayeredConfig();
            services.AddScoped(typeof(IConfigProjects), e => new iniFileConfigServer { filePath =AppDomain.CurrentDomain.BaseDirectory+"mail.ini"}); //这样写很麻烦

            //services.AddScoped<ILogProvider, ConsoleILogProvider>();
            services.AddConsoleLog();
            services.AddScoped<IMailProjects, ConsoleMailProjects>();

            using (var sp = services.BuildServiceProvider())
            {
                // 第一个根对象 只能用ServerLocaction
                IMailProjects mail = sp.GetRequiredService<IMailProjects>();
                mail.Send("我是标题", "aggie", "我是内容");
            }
        }
    }
}
